﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Drawing;

namespace IFD2
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Init(object sender, EventArgs e)//Init事件才早于具体页面的Load事件！
        {
            if (Session["USER"] == null || Session["USER"].ToString() == "" || Application["VERTYPE"] == null)
            {
                Session.Clear();
                Response.Redirect("~/Default.aspx");
                return;
            }

            if (Application["VERTYPE"].ToString() == "RUN")
            {
                lblVersion.Text = "";
            }
            else if (Application["VERTYPE"].ToString() == "SHADOW")
            {
                lblVersion.Text = (string)base.GetLocalResourceObject("tipVerShadow.Text");
                lblVersion.ForeColor = Color.FromArgb(0, 255, 136);//#00ff88
            }
            else if (Application["VERTYPE"].ToString() == "ALPHA")
            {
                lblVersion.Text = (string)base.GetLocalResourceObject("tipVerAlpha.Text");
                lblVersion.ForeColor = Color.FromArgb(0, 255, 136);//#00ff88
            }
            else if (Application["VERTYPE"].ToString() == "BETA")
            {
                lblVersion.Text = (string)base.GetLocalResourceObject("tipVerBeta.Text");
                lblVersion.ForeColor = Color.FromArgb(0, 255, 136);//#00ff88
            }
            else
            {
                lblVersion.Text = Application["VERSION"].ToString() + "?";
                lblVersion.ForeColor = Color.FromArgb(0, 255, 136);//#00ff88
            }
            lblUser.Text = Session["USER"].ToString();

            //隐藏无关菜单
            DataTable myTab = new DataTable();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "bll_user_get_office_types";
            SqlParameter para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
            StringBuilder role_office_types = new StringBuilder("", 100);//注意，如果用户兼25个角色就会超界！
            try
            {
                TinyDAL.Exec(ref cmd, ref myTab);
                foreach (DataRow row in myTab.Rows)
                {
                    role_office_types.Append(row["type"].ToString() + ",");
                }
            }
            catch (Exception ex)
            {
                return;
            }
            string user_types = role_office_types.ToString();
            Session["OFFICE_LIST"] = user_types;
                       
        }

        protected void Page_Load(object sender, EventArgs e)//Load事件中才会在每次提交页面后更新！
        {
            lblUTC.Text = TinyDAL.Get_DB_UTC_Time();//年月日间要用'/'分割，不能用'-'，否则JS不能将字符串转换为日期型！
        }
    }
}